"""
URL configuration for strat_django project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""

from django.contrib import admin
from django.urls import path, include, reverse
from django.shortcuts import HttpResponse
from books import views


def index(request):
    # reverse("") 输入url的name 反向解析URL
    print(reverse("index"))
    # http://127.0.0.1:8000/books/1/ 传参的方式
    print(reverse("book_str", kwargs={"book_str": "python"}))
    print(reverse("book_slug", args=("python1",)))
    # http://127.0.0.1:8000/books?name=1 查询字符串的方式只能用拼接的方式
    print(reverse("book1")+"?name=adsad&author=adsad")
    print(reverse("movies:movie_list"))  # 引用movies命名空间的URL配置
    return HttpResponse("Hello, world. You're at the strat_django index.")


urlpatterns = [
    path("", index, name="index"),
    path("admin/", admin.site.urls, name="admin"),
    path("books", views.book1, name="book1"),
    path("books/<int:book_id>", views.book2, name="book2"),  # book_id默认为string类型，需要加上int来指定
    path("books/str/<str:book_str>", views.book_str, name="book_str"),  # str类型,不能带斜线”/“
    path("books/slug/<slug:book_slug>/", views.book_slug, name="book_slug"),  # slug类型，只能包含字母、数字、下划线（_）、连字符（-），且必须以字母或数字开头
    path("books/path/<path:book_path>", views.book_path, name="book_path"),  # path类型，可以包含斜线，可以是任意字符
    path('movies/', include('movies.urls'))  # 包含movies子应用的URL配置
]
